import request from '@/utils/request'
import { Config, Tag, Article, ArticlePage, Classify, Tree, BlogLogPage, Content, DynamicPage } from '@/api/type'

/**
 * 获取博主信息
 * @returns
 */
export const getDesc = () => {
  return request<Config[]>({
    method: 'get',
    url: '/blog/desc'
  })
}

/**
 * 获取所有标签
 * @returns
 */
export const getTags = () => {
  return request<Tag[]>({
    method: 'get',
    url: '/blog/tags'
  })
}

/**
 * 获取随机文章
 * @returns
 */
export const getRandomArticles = () => {
  return request<Article[]>({
    method: 'get',
    url: '/blog/random/articles'
  })
}

/**
 * 分页获取最新顺序文章
 * @param current
 * @returns
 */
export const getPageArticles = (params: { queryParam?: string | unknown, tagName?: string, current: number, classifyId: number }) => {
  return request<ArticlePage>({
    method: 'get',
    url: '/blog/articles/page',
    params
  })
}

/**
 * 根据父id获取分类
 * @param pid
 * @returns
 */
export const getClassifies = (pid: number) => {
  return request<Classify[]>({
    method: 'get',
    url: '/blog/classify/' + pid
  })
}

/**
 * 根据父id获取树结构分类
 * @param pid
 * @returns
 */
export const getClassifyTree = (pid: number) => {
  return request<Tree[]>({
    method: 'get',
    url: '/blog/classify/tree/' + pid
  })
}

/**
 * 获取父id或以上id
 * @param classifyId 
 */
export const getClassifyParent = (classifyId: number) => {
  return request<Classify[]>({
    method: 'get',
    url: '/blog/classify/parent/' + classifyId
  })
}

/**
 * 分页获取归档日志
 * @param current 
 * @returns 
 */
export const getBlogLogs = (current: number) => {
  return request<BlogLogPage>({
    method: 'get',
    url: '/blog/log/' + current
  })
}

/**
 * 获取文章内容
 * @param articleId 
 */
export const getContent = (articleId: number) => {
  return request<Content>({
    method: 'get',
    url: '/blog/content/' + articleId
  })
}

export const getDynamic = (current: number) => {
  return request<DynamicPage>({
    method: 'get',
    url: '/blog/dynamic/' + current
  })
}